import { defineStore } from "pinia";
import { accountInfo, permMenu } from "@/api/account";

export const useUserStore = defineStore("user", {
  state() {
    return {
      roles: [],
      perms: [],
      userInfo: null,
    };
  },
  actions: {
    //获取用户详细信息
    getUserInfo() {
      return new Promise((resolve, reject) => {
        accountInfo()
          .then((res: any) => {
            resolve(res.data);
          })
          .catch((err: any) => {
            reject(err);
          });
      });
    },
    //获取用户权限、菜单
    getPermMenus() {
      return new Promise((resolve, reject) => {
        permMenu()
          .then((res: any) => {
            resolve(res.data);
          })
          .catch((err: any) => {
            reject(err);
          });
      });
    },
    setUserInfo(info) {
      this.userInfo = info;
    },
    setPerms(perms) {
      this.perms = perms;
    }
  },
  getters: {},
});
